<template>
	<div>
		<div class="codeBox">
			<p class="title">初始化数据</p>
			<p class="soild"></p>
			<div>
				<!--  -->
				<el-button @click="buttonClick('IsCreateMenuNew')">菜单
				<i class="el-icon-success el-icon--right" v-if="!dataForm.bm_IsMenu" :class="{ active: codeForm.IsCreateMenuNew == 1 }" ></i>
				<span v-else @click.stop="pardomGeneration('IsCreateMenuNew')" class="perdomTitle">重新生成</span>
				</el-button>
				<el-button @click="buttonClick('IsCreateButtonNew')">按钮
				<i class="el-icon-success el-icon--right"  v-if="!dataForm.bm_IsButton"	:class="{ active: codeForm.IsCreateButtonNew == 1 }" ></i>
				<span v-else @click.stop="pardomGeneration('IsCreateButtonNew')" class="perdomTitle">重新生成</span>
				</el-button>
			</div>
		</div>
<!-- 		<div class="codeBox">
			<p class="title">前端代码</p>
			<p class="soild"></p>
			<div>
				<el-button>列表页面<i class="el-icon-success el-icon--right"></i></el-button>
				<el-button>新增、编辑页面<i class="el-icon-success el-icon--right"></i></el-button>
				<el-button>查看页面<i class="el-icon-success el-icon--right"></i></el-button>
			</div>
		</div> -->
		<div class="codeBox">
			<p class="title">后端页面</p>
			<p class="soild"></p>
			<div>
				<el-button @click="buttonClick('IsEntityNew')">实体
					<i class="el-icon-success el-icon--right" :class="{ active: codeForm.IsEntityNew == 1 }"  v-if="!dataForm.bm_IsEntity"></i>
					<span v-else @click.stop="pardomGeneration('IsEntityNew')" class="perdomTitle">重新生成</span>
				</el-button>
				<el-button @click="buttonClick('IsServiceNew')">Service
					<i class="el-icon-success el-icon--right" :class="{ active: codeForm.IsServiceNew == 1 }"  v-if="!dataForm.bm_IsService"></i>
					<span v-else @click.stop="pardomGeneration('IsServiceNew')" class="perdomTitle">重新生成</span>
				</el-button>
				<el-button @click="buttonClick('IsControllerNew')">接口
					<i class="el-icon-success el-icon--right" :class="{ active: codeForm.IsControllerNew == 1 }" v-if="!dataForm.bm_IsController"></i>
					<span v-else @click.stop="pardomGeneration('IsControllerNew')" class="perdomTitle">重新生成</span>
				</el-button>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		GetBillData,
		BillMachineCreateCode
	} from '@/api/apis/documentManagement'
	export default{
		data(){
			return{
				Bm_id:'',
				codeForm:{
					IsCreateMenuNew:0,
					IsCreateButtonNew:0,
					IsEntityNew:0,
					IsControllerNew:0,
					IsServiceNew:0
				},
				dataForm:{
					bm_IsMenu:0,
					bm_IsButton:0,
					bm_IsEntity:0,
					bm_IsService:0,
					bm_IsController:0,
				},
			}
		},
		methods:{
			initPage(id){
				this.Bm_id = id
				this.getDetail(id)
			},
			async getDetail(id) {
				this.openLoading('details')
				let res = await GetBillData({
					id: id
				})
				// console.log(res)
				if (res.success == 'true') {
					for(let i in this.dataForm){
						this.dataForm[i] = res.data[0][i]
					}
				}
			},
			buttonClick(row){
				this.$set(this.codeForm,row,this.codeForm[row] == 1 ?0:1)
			},
			pardomGeneration(row){
				this.$tipConfirm("是否重新生成",'info',true).then(res=>{
					this.$tipConfirm("请再次确认是否重新生成",'info',true).then(res=>{
						this.generateAgain(row)
					})
				})
			},
			async generateAgain(row){
				let params = {
					Bm_id:this.Bm_id,
					IsCreateMenuNew:0,
					IsCreateButtonNew:0,
					IsEntityNew:0,
					IsServiceNew:0,
					IsControllerNew:0,
				}
				params[row] = 1
				let res = await BillMachineCreateCode(params)
				if (res.code ==1) {
					this.$vmNews('代码生成成功!</br>'+res.data[0])
				} else if (res.success =="false") {
					let title = res.message
					this.$message.error(res.message);
				}
			},
			async saveDto(){
				let params = {
					Bm_id:this.Bm_id,
					...this.codeForm
				}
				let res = await BillMachineCreateCode(params)
				if (res.code ==1) {
					this.$vmNews('代码生成成功!</br>'+res.data[0])
				} else if (res.success =="false") {
					let title = res.message
					this.$message.error(res.message);
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	$activeColor: var(--bg-color, "#00aaff");
	.codeBox {
		padding-bottom: 50px;

		.soild {
			margin-top: 16px;
			margin-bottom: 12px;
			height: 1px;
			background-color: #f2f2f2;
		}

		.title {
			border-left: 3px solid #2261f6;
			padding-left: 10px;
		}

		.active {
			color: $activeColor;
		}
		.perdomTitle{
			font-size: 12px;
			color:$activeColor
		}
	}
</style>